package com.flying.invest.invest.model;

import java.util.Date;

import com.flying.common.util.Codes;
import com.flying.framework.annotation.ConstantEnum;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.ServiceField;
import com.flying.framework.annotation.ServiceFieldParam;
import com.flying.framework.data.Data;
import com.flying.framework.data.DataSerializable;
import com.flying.framework.metadata.Meta;
import com.flying.invest.assets.model.Assets;
import com.flying.invest.invest.TransactionType;
import com.flying.invest.strategy.model.Strategy;
import com.flying.invest.strategy.model.StrategyType;

@SuppressWarnings("serial")
@Meta(id="i_investment_transaction",title="", table="i_investment_transaction", primaryKeys={"transaction_id"})
public class InvestmentTransaction extends Data implements DataSerializable {
	public final static String ENTITY_NAME = "i_investment_transaction";
	
	public final static String TRANSACTION_ID = "transaction_id";
	public final static String INVEST_ID = "invest_id";
	public final static String ASSETS_ID = "assets_id";
	public final static String USER_ID = "user_id";
	public final static String SUGGESTION_ID = "suggestion_id";
	public final static String STRATEGY_ID = "strategy_id";
	public final static String TRANSACTION_TYPE = "transaction_type";
	public final static String TRANSACTION_METHOD = "transaction_method";
	public final static String OBJECTIVE = "objective";
	public final static String AMOUNT = "amount";
	public final static String QUANTITY = "quantity";
	public final static String TAX = "tax";
	public final static String PRICE = "price";
	public final static String CURRENCY = "currency";
	public final static String CURRENCY_RATE = "currency_rate";
	public final static String TRANSACTION_DATE = "transaction_date";
	public final static String TRANSACTION_FINISH_TIME = "transaction_finish_time";
	public final static String NUM = "num";
	public final static String TERM_TYPE = "term_type";
	public final static String STATUS = "status";
	public final static String REMARKS = "remarks";
	public final static String CREATOR = "creator";
	public final static String CREATE_TIME = "create_time";
	public final static String UPDATOR = "updator";
	public final static String UPDATE_TIME = "update_time";
	
	public enum Status implements ConstantEnum<Integer> {
		PROCESSING(0, "交易中"), SUCCESS(1, "交易成功"), FAILED(2, "交易失败");

		public final int value;
		public final String remarks;

		Status(int value, String remarks) {
			this.value = value;
			this.remarks = remarks;
		}
		
		@Override
		public Integer value() {
			return this.value;
		}

		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum Method implements ConstantEnum<Integer> {
		NONE(0, "随性交易"), MANUAL(1, "手动交易"), STRATEGIED(2, "策略交易");

		public final int value;
		public final String remarks;

		Method(int value, String remarks) {
			this.value = value;
			this.remarks = remarks;
		}
		
		@Override
		public Integer value() {
			return this.value;
		}

		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum Objective implements ConstantEnum<Integer> {
		ATTEMP(1, "试验仓"), HOUSE(2, "建仓"), TRANS(3, "交易"), NONE(0, "无");

		public final int value;
		public final String remarks;

		Objective(int value, String remarks) {
			this.value = value;
			this.remarks = remarks;
		}
		
		@Override
		public Integer value() {
			return this.value;
		}

		@Override
		public String text() {
			return remarks;
		}
	}
	
	
	@Param(value=TRANSACTION_ID,   required=true,   maxlength=0,	desc="ID" , generator=Codes.AUTO_INCREMENT)
	private Long transactionId;
	
	@Param(value=INVEST_ID,   required=true,   maxlength=0,	desc="投资ID" )
	private Long investId;
	
	@Param(value=ASSETS_ID,   required=true,   maxlength=0,	desc="投资品种ID" )
	private Long assetsId;
	
	@Param(value=USER_ID,   required=true,   maxlength=0,	desc="所属用户ID" )
	private Long userId;
	
	@Param(value=SUGGESTION_ID,   required=false,   maxlength=0,	desc="投资建议ID" )
	private Long suggestionId;
	
	@Param(value=STRATEGY_ID,   required=false,   maxlength=0,	desc="策略ID" )
	private Long strategyId;
	
	@Param(value=TRANSACTION_TYPE,   required=true, enumClass=TransactionType.class,   maxlength=0,	desc="交易类型" )
	private Integer transactionType;
	
	@Param(value=TRANSACTION_METHOD,   required=false,   maxlength=0, enumClass=Method.class,	desc="交易方法（0：随性交易；1：策略交易）" )
	private Integer transactionMethod;
	
	@Param(value=OBJECTIVE,   required=false,   maxlength=0, enumClass=Objective.class,	desc="交易目的（0：无；1：预备；2：建仓；3：策略）" )
	private Integer objective;
	
	@Param(value=AMOUNT,   required=true,   maxlength=0,	desc="交易金额" )
	private Double amount;
	
	@Param(value=QUANTITY,   required=false,   maxlength=0,	desc="交易数量" )
	private Double quantity;
	
	@Param(value=TAX,   required=false,   maxlength=0,	desc="交易税额" )
	private Double tax;
	
	@Param(value=PRICE,   required=false,   maxlength=0,	desc="交易价格" )
	private Double price;
	
	@Param(value=CURRENCY,   required=false,   maxlength=10,	desc="币种" )
	private String currency;
	
	@Param(value=CURRENCY_RATE,   required=false,   maxlength=0,	desc="汇率" )
	private Double currencyRate;
	
	@Param(value=TRANSACTION_DATE,   required=false,   maxlength=0,	desc="交易日期" )
	private Date transactionDate;

	@Param(value=TRANSACTION_FINISH_TIME,   required=false,   maxlength=0,	desc="交易完成时间" )
	private Date transactionFinishTime;
	
	@Param(value=NUM,   required=false,   maxlength=0,	desc="投资期数" )
	private Long num;
	
	@Param(value=TERM_TYPE,   required=false,   maxlength=0,	desc="投资周期" )
	private Integer termType;
	
	@Param(value=STATUS,   required=false,   maxlength=0, enumClass=Status.class,	desc="状态" )
	private Integer status;
	
	@Param(value=REMARKS,   required=false,   maxlength=400,	desc="说明" )
	private String remarks;
	
	@Param(value=CREATOR,   required=false,   maxlength=40,	desc="创建人" )
	private String creator;
	
	@Param(value=CREATE_TIME,   required=false,   maxlength=0,	desc="创建时间" )
	private Date createTime;
	
	@Param(value=UPDATOR,   required=false,   maxlength=40,	desc="修改人" )
	private String updator;
	
	@Param(value=UPDATE_TIME,   required=false,   maxlength=0,	desc="修改时间" )
	private Date updateTime;
	//
	@ServiceField(serviceId="AssetsService:findById2", params={@ServiceFieldParam(param=Assets.ASSETS_ID, value="$"+ASSETS_ID)})
	@Param(value="assets",   required=false,	desc="资产", ignored=true)
	private Assets assets;

	@ServiceField(serviceId="StrategyTypeService:findByStrategyId", params={@ServiceFieldParam(param=Strategy.STRATEGY_ID, value="$"+STRATEGY_ID)})
	@Param(value="strategyType",   required=false,	desc="策略类型", ignored=true)
	private StrategyType strategyType;
	
	
	public Long getTransactionId() {
		return this.transactionId;
	}
	
	public void setTransactionId(Long transactionId) {
		this.transactionId = transactionId;
	}
	
	public Long getInvestId() {
		return this.investId;
	}
	
	public void setInvestId(Long investId) {
		this.investId = investId;
	}
	
	public Long getAssetsId() {
		return this.assetsId;
	}
	
	public void setAssetsId(Long assetsId) {
		this.assetsId = assetsId;
	}
	
	public Long getUserId() {
		return this.userId;
	}
	
	public void setUserId(Long userId) {
		this.userId = userId;
	}
	
	public Long getSuggestionId() {
		return this.suggestionId;
	}
	
	public void setSuggestionId(Long suggestionId) {
		this.suggestionId = suggestionId;
	}
	
	public Long getStrategyId() {
		return this.strategyId;
	}
	
	public void setStrategyId(Long strategyId) {
		this.strategyId = strategyId;
	}
	
	public Integer getTransactionType() {
		return this.transactionType;
	}
	
	public void setTransactionType(Integer transactionType) {
		this.transactionType = transactionType;
	}
	
	public Integer getTransactionMethod() {
		return this.transactionMethod;
	}
	
	public void setTransactionMethod(Integer transactionMethod) {
		this.transactionMethod = transactionMethod;
	}
	
	public Integer getObjective() {
		return this.objective;
	}
	
	public void setObjective(Integer objective) {
		this.objective = objective;
	}
	
	public Double getAmount() {
		return this.amount;
	}
	
	public void setAmount(Double amount) {
		this.amount = amount;
	}
	
	public Double getQuantity() {
		return this.quantity;
	}
	
	public void setQuantity(Double quantity) {
		this.quantity = quantity;
	}
	
	public Double getTax() {
		return this.tax;
	}
	
	public void setTax(Double tax) {
		this.tax = tax;
	}
	
	public Double getPrice() {
		return this.price;
	}
	
	public void setPrice(Double price) {
		this.price = price;
	}
	
	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public Double getCurrencyRate() {
		return currencyRate;
	}

	public void setCurrencyRate(Double currencyRate) {
		this.currencyRate = currencyRate;
	}

	public Date getTransactionDate() {
		return this.transactionDate;
	}
	
	public void setTransactionDate(Date transactionDate) {
		this.transactionDate = transactionDate;
	}
	
	public Date getTransactionFinishTime() {
		return transactionFinishTime;
	}

	public void setTransactionFinishTime(Date transactionFinishTime) {
		this.transactionFinishTime = transactionFinishTime;
	}

	public Long getNum() {
		return this.num;
	}
	
	public void setNum(Long num) {
		this.num = num;
	}
	
	public Integer getTermType() {
		return termType;
	}

	public void setTermType(Integer termType) {
		this.termType = termType;
	}

	public Integer getStatus() {
		return this.status;
	}
	
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getCreator() {
		return this.creator;
	}
	
	public void setCreator(String creator) {
		this.creator = creator;
	}
	
	public Date getCreateTime() {
		return this.createTime;
	}
	
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public String getUpdator() {
		return this.updator;
	}
	
	public void setUpdator(String updator) {
		this.updator = updator;
	}
	
	public Date getUpdateTime() {
		return this.updateTime;
	}
	
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	//
	public Assets getAssets() {
		return assets;
	}
	
	public StrategyType getStrategyType() {
		return strategyType;
	}

	public String getAssetsName() {
		var t = this.getAssets();
		return t == null? null: t.getName();
	}

	public String getStrategyName() {
		var t = this.getStrategyType();
		return t == null? null: t.getName();
	}
	
}